package com.bawei.yuekao.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SPUtils {
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    //单例模式：构造私有化+自行实例化+提供公开方法访问
    private SPUtils(Context context){
        sharedPreferences = context.getSharedPreferences("music",Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }
    private static SPUtils spUtils;
    public synchronized static SPUtils getInstance(Context context){
        if(spUtils == null){
            spUtils = new SPUtils(context);
        }
        return spUtils;
    }



    public void putString(String key,String value){
        editor.putString(key,value);
        editor.commit();

    }

    public String getString(String key){
        return sharedPreferences.getString(key, "");
    }


}
